package com.gambi.tapestry.services.gwt;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class GWTComponentEventSource {

	private static final long serialVersionUID = 6853746514825397823L;

	/*
	 * Manage the mapping between a component and its GWT Event names
	 */
	private Map<String, Set<String>> mapping = new HashMap<String, Set<String>>();

	public void registerComponent(String component) {
		System.out.println("GWTComponentEventSource.registerComponent() " + component );
		if (!mapping.containsKey(component)) {
			mapping.put(component, new HashSet<String>());
		}
	}

	public void addEventToComponent(String component, String eventName) {
		System.out.println("GWTComponentEventSource.addEventToComponent() component " + component );
		System.out.println("GWTComponentEventSource.addEventToComponent() eventName " + eventName );
		Set<String> componentEvents = mapping.get(component);
		if (componentEvents != null) {
			componentEvents.add(eventName);
		}
	}

	public Set<String> getEventSetForComponent(String componentClassName) {
		return mapping.get( componentClassName );
	}
}
